package org.study.springboot.learning.proxy;

import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.NoOp;

/**
 * <p>Title: TesProxy <p>
 * <p>Description: TODO<p>
 *
 * @Author ZhangSY
 * @Date 2021/6/24 23:52
 * @Version v1.0
 **/
public class TesProxy {
    public static void main(String[] args) {
        DaoProxy daoProxy = new DaoProxy();
        DaoAnotherProxy daoAnotherProxy = new DaoAnotherProxy();
        Enhancer enhancer = new Enhancer();
        //设置要代理的类
        enhancer.setSuperclass(Dao.class);
        //设置设置回调即为MethodInterceptor的实现类
        //enhancer.setCallback(daoProxy);
        enhancer.setCallbacks(new Callback[]{daoProxy,daoAnotherProxy, NoOp.INSTANCE});
        enhancer.setCallbackFilter(new DaoFilter());
        //生成代理对象，注意需要强转
        Dao dao = (Dao) enhancer.create();
        dao.select();
        dao.update();
    }
}
